/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * GenInterface.java
 *
 * Created on 14/Mai/2011, 18:13:09
 */
package infoPackage;

import algorithms.*;
import java.awt.event.ActionEvent;
import java.io.File;
import java.io.FileNotFoundException;
import javax.swing.*;

/**
 *
 * @author FTeixeira
 */
public class GenInterface extends javax.swing.JFrame {

    LoadInfo loadinfo = null;
    GeneticAlgorithm genetics = null;
    public JFileChooser fc = new JFileChooser();
    public File config_file;
    public boolean elitism = false;
    public int elitismNum = 0;
    public int generations = 100;
    public boolean mult_crossover = false;
    public int maxDam = 3;
    public float minDistance = 3;
    public int nChromo = 10;

    /** Creates new form GenInterface */
    public GenInterface(String file) {
        initComponents();
        otherInit(file);
    }

    /*public static File initFile(String args[]) {
    if (args.length == 0) {
    //System.out.println("Configuration file not specified. Program will exit.");
    //System.exit(-1);
    File file = new File("rivers.xml");
    return file;
    }
    if (args.length == 1) {
    String currentDir = System.getProperty("user.dir");
    System.out.println(currentDir);
    File file = new File(args[0]);
    return file;
    }
    return null;
    }*/
    private void otherInit(String file) {
        enableApplication(false);
        if (file.equals("") || file == null) {
            readFile_button.setEnabled(false);
            setVisible(true);
            file_buttonActionPerformed(new ActionEvent(file_button, ActionEvent.ACTION_PERFORMED, file));
        } else {
            file_textField.setText(file);
            readFile_button.setEnabled(true);
        }
    }

    public void enableApplication(boolean enabled) {
        commands_field.setEnabled(enabled);
        chromosomes_textarea.setEnabled(enabled);
        nChromo_spinner.setEnabled(enabled);
        elitism_checkbox.setEnabled(enabled);
        if (enabled && elitism_checkbox.isSelected()) {
            elitismNum_spinner.setEnabled(enabled);
        }
        maxDam_spinner.setEnabled(enabled);
        minDistance_spinner.setEnabled(enabled);
        start_button.setEnabled(enabled);
        mult_crossover_checkBox.setEnabled(enabled);
        generations_spinner.setEnabled(enabled);
    }

    public void clearData() {
        chromosomes_textarea.setText("");
        file_textField.setText("");
        //commands_field.setText("");
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        controls = new javax.swing.JPanel();
        file_textField = new javax.swing.JTextField();
        file_button = new javax.swing.JButton();
        file_label = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        mult_crossover_checkBox = new javax.swing.JCheckBox();
        jLabel1 = new javax.swing.JLabel();
        nChromo_spinner = new javax.swing.JSpinner();
        jLabel2 = new javax.swing.JLabel();
        maxDam_spinner = new javax.swing.JSpinner();
        jLabel3 = new javax.swing.JLabel();
        minDistance_spinner = new javax.swing.JSpinner();
        elitism_checkbox = new javax.swing.JCheckBox();
        elitismNum_spinner = new javax.swing.JSpinner();
        start_button = new java.awt.Button();
        generations_spinner = new javax.swing.JSpinner();
        Generations = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        commands_field = new javax.swing.JTextArea();
        jLabel4 = new javax.swing.JLabel();
        readFile_button = new javax.swing.JButton();
        close_app = new javax.swing.JButton();
        result = new javax.swing.JPanel();
        scroll = new javax.swing.JScrollBar();
        jScrollPane1 = new javax.swing.JScrollPane();
        chromosomes_textarea = new javax.swing.JTextArea();
        menuBar = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenu2 = new javax.swing.JMenu();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        file_textField.setText("Please chose a configuration file...");
        file_textField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                file_textFieldActionPerformed(evt);
            }
        });

        file_button.setText("Open");
        file_button.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                file_buttonActionPerformed(evt);
            }
        });

        file_label.setText("Configuration File");

        mult_crossover_checkBox.setText(" Multiple Crossover");
        mult_crossover_checkBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mult_crossover_checkBoxActionPerformed(evt);
            }
        });

        jLabel1.setText("Number of Chromosomes");

        nChromo_spinner.setValue(10);
        nChromo_spinner.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                nChromo_spinnerStateChanged(evt);
            }
        });

        jLabel2.setText("Max number of dams");

        maxDam_spinner.setValue(3);
        maxDam_spinner.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                maxDam_spinnerStateChanged(evt);
            }
        });

        jLabel3.setText("Min distance between dams");

        minDistance_spinner.setValue(3);
        minDistance_spinner.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                minDistance_spinnerStateChanged(evt);
            }
        });

        elitism_checkbox.setText("Elitism");
        elitism_checkbox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                elitism_checkboxActionPerformed(evt);
            }
        });

        elitismNum_spinner.setValue(2);
        elitismNum_spinner.setEnabled(false);

        start_button.setLabel("Start");
        start_button.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                start_buttonActionPerformed(evt);
            }
        });

        generations_spinner.setValue(100);
        generations_spinner.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                generations_spinnerStateChanged(evt);
            }
        });

        Generations.setText("Generations");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(nChromo_spinner, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 165, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(maxDam_spinner, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, 346, Short.MAX_VALUE)))
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(minDistance_spinner, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addComponent(generations_spinner, javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(elitismNum_spinner, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 49, Short.MAX_VALUE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(6, 6, 6)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(mult_crossover_checkBox, javax.swing.GroupLayout.PREFERRED_SIZE, 119, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(elitism_checkbox, javax.swing.GroupLayout.PREFERRED_SIZE, 337, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addComponent(Generations)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addGap(225, 225, 225))))))
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(start_button, javax.swing.GroupLayout.PREFERRED_SIZE, 293, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(127, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(nChromo_spinner, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 9, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(maxDam_spinner, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(minDistance_spinner, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(elitismNum_spinner, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(elitism_checkbox))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(mult_crossover_checkBox)
                .addGap(14, 14, 14)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(generations_spinner, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(Generations))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 55, Short.MAX_VALUE)
                .addComponent(start_button, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        commands_field.setColumns(20);
        commands_field.setRows(5);
        jScrollPane2.setViewportView(commands_field);

        jLabel4.setText("Commands:");

        readFile_button.setText("Read");
        readFile_button.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                readFile_buttonActionPerformed(evt);
            }
        });

        close_app.setText("Close");
        close_app.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                close_appActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout controlsLayout = new javax.swing.GroupLayout(controls);
        controls.setLayout(controlsLayout);
        controlsLayout.setHorizontalGroup(
            controlsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(controlsLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(controlsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(file_label)
                    .addGroup(controlsLayout.createSequentialGroup()
                        .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 81, Short.MAX_VALUE)
                        .addComponent(close_app))
                    .addGroup(controlsLayout.createSequentialGroup()
                        .addComponent(file_button, javax.swing.GroupLayout.PREFERRED_SIZE, 77, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(readFile_button, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jPanel1, 0, 292, Short.MAX_VALUE)
                    .addComponent(file_textField, javax.swing.GroupLayout.DEFAULT_SIZE, 292, Short.MAX_VALUE)
                    .addComponent(jScrollPane2))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        controlsLayout.setVerticalGroup(
            controlsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(controlsLayout.createSequentialGroup()
                .addGap(19, 19, 19)
                .addComponent(file_label)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(file_textField, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(controlsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(file_button)
                    .addComponent(readFile_button))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGroup(controlsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(controlsLayout.createSequentialGroup()
                        .addGap(21, 21, 21)
                        .addComponent(jLabel4))
                    .addGroup(controlsLayout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(close_app)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 151, Short.MAX_VALUE)
                .addContainerGap())
        );

        chromosomes_textarea.setColumns(20);
        chromosomes_textarea.setRows(5);
        jScrollPane1.setViewportView(chromosomes_textarea);

        javax.swing.GroupLayout resultLayout = new javax.swing.GroupLayout(result);
        result.setLayout(resultLayout);
        resultLayout.setHorizontalGroup(
            resultLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, resultLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 389, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(scroll, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        resultLayout.setVerticalGroup(
            resultLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(resultLayout.createSequentialGroup()
                .addGap(11, 11, 11)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 572, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, resultLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(scroll, javax.swing.GroupLayout.DEFAULT_SIZE, 572, Short.MAX_VALUE))
        );

        jMenu1.setText("File");
        menuBar.add(jMenu1);

        jMenu2.setText("Edit");
        menuBar.add(jMenu2);

        setJMenuBar(menuBar);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(controls, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(36, 36, 36)
                .addComponent(result, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(18, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(result, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addComponent(controls, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void file_textFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_file_textFieldActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_file_textFieldActionPerformed

    private void mult_crossover_checkBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mult_crossover_checkBoxActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_mult_crossover_checkBoxActionPerformed

    private void elitism_checkboxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_elitism_checkboxActionPerformed
        elitism = elitism_checkbox.isSelected();
        elitismNum_spinner.setEnabled(elitism);
    }//GEN-LAST:event_elitism_checkboxActionPerformed

    private void file_buttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_file_buttonActionPerformed
        int returnVal = fc.showOpenDialog(null);

        if (returnVal == JFileChooser.APPROVE_OPTION) {
            config_file = fc.getSelectedFile();
            file_textField.setText(config_file.getPath());
            readFile_button.setEnabled(true);
        } else {
            file_textField.setText("Please chose a configuration file...");
            enableApplication(false);
        }
    }//GEN-LAST:event_file_buttonActionPerformed

    private void nChromo_spinnerStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_nChromo_spinnerStateChanged
        // TODO add your handling code here:
        nChromo = (Integer) nChromo_spinner.getValue();
    }//GEN-LAST:event_nChromo_spinnerStateChanged

    private void maxDam_spinnerStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_maxDam_spinnerStateChanged
        // TODO add your handling code here:
        maxDam = (Integer) maxDam_spinner.getValue();
    }//GEN-LAST:event_maxDam_spinnerStateChanged

    private void minDistance_spinnerStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_minDistance_spinnerStateChanged
        // TODO add your handling code here:
        minDistance = (float) (Integer) minDistance_spinner.getValue();
    }//GEN-LAST:event_minDistance_spinnerStateChanged

    private void start_buttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_start_buttonActionPerformed
        // TODO add your handling code here:
        genetics = new GeneticAlgorithm(loadinfo.nSections, loadinfo.rivers,
                loadinfo.sections, nChromo, elitism, elitismNum, mult_crossover,
                maxDam, minDistance);
        for (int i = 0; i < generations; i++) {
            System.out.println("\n########### Generation No " + i + " ###########\n");
            genetics.nextGeneration();
            System.out.println("\n############## ENDOF " + i + " ################\n");
        }
        genetics.printPopulation(genetics.chromosomes);
    }//GEN-LAST:event_start_buttonActionPerformed

    private void readFile_buttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_readFile_buttonActionPerformed
        // TODO add your handling code here:
        File file = new File(file_textField.getText());
        try {
            //clearData();
            loadinfo = new LoadInfo();
            if (loadinfo.xmlParser(file));
            commands_field.setText(" :: " + file.getName() + " successfully read!\n");
            commands_field.append("     Number of rivers: " + loadinfo.nRivers + "\n");
            commands_field.append("     Number of sections: " + loadinfo.nSections + "\n");
            enableApplication(true);
        } catch (FileNotFoundException e) {
            enableApplication(false);
            commands_field.setText(" :: File not found!\n");
        } catch (Exception e) {
            enableApplication(false);
            commands_field.setText(" :: Bad configuration file. Program will exit.\n");
        }
        readFile_button.setEnabled(false);
    }//GEN-LAST:event_readFile_buttonActionPerformed

    private void close_appActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_close_appActionPerformed
        // TODO add your handling code here:
        try {
        } catch (Exception e) {
            System.out.println("The application will now close.");
        }
        System.out.println(" All rights reserved: FEUP - May, 2011");
        System.exit(1);
    }//GEN-LAST:event_close_appActionPerformed

    private void generations_spinnerStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_generations_spinnerStateChanged
        // TODO add your handling code here:
        generations = (Integer) generations_spinner.getValue();
    }//GEN-LAST:event_generations_spinnerStateChanged

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new GenInterface("").setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel Generations;
    private javax.swing.JTextArea chromosomes_textarea;
    private javax.swing.JButton close_app;
    private javax.swing.JTextArea commands_field;
    private javax.swing.JPanel controls;
    private javax.swing.JSpinner elitismNum_spinner;
    private javax.swing.JCheckBox elitism_checkbox;
    private javax.swing.JButton file_button;
    private javax.swing.JLabel file_label;
    private javax.swing.JTextField file_textField;
    private javax.swing.JSpinner generations_spinner;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JSpinner maxDam_spinner;
    private javax.swing.JMenuBar menuBar;
    private javax.swing.JSpinner minDistance_spinner;
    private javax.swing.JCheckBox mult_crossover_checkBox;
    private javax.swing.JSpinner nChromo_spinner;
    private javax.swing.JButton readFile_button;
    private javax.swing.JPanel result;
    private javax.swing.JScrollBar scroll;
    private java.awt.Button start_button;
    // End of variables declaration//GEN-END:variables
}
